package com.graduationdesign.zengyan.graduationdesignapp.utils;


import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by ZengYan on 2018/4/15.
 *
 * @desc :
 */
public class Api {

    private static Retrofit INSTANCE;

    public static Retrofit getRetrofit() {
        if (INSTANCE == null) {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new RetrofitLogger());
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            //添加拦截器到OkHttp，这是最关键的
            httpClient.addInterceptor(logging);

            INSTANCE = new Retrofit.Builder()
                    .baseUrl(Config.baseUrl)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .client(httpClient.build())
                    .build();
        }
        return INSTANCE;
    }

}
